package dao

func Offset(page, size int) (offset int, limit int) {
	if page <= 0 {
		page = 0
	}
	if size <= 0 {
		size = 0
	}
	if page <= 0 && size <= 0 {
		return -1, -1
	}
	if size >= 2000 {
		limit = 2000
	} else {
		limit = size
	}
	offset = (page - 1) * limit
	return
}

// GetPageOffset 获取分页Offset
func GetPageOffset(page, limit int) int {
	offset := -1
	if page > 0 && limit > 0 {
		offset = (page - 1) * limit
	}
	return offset
}

// GetPageLimit 获取分页的offset
func GetPageLimit(limit int) int {
	if limit <= 0 {
		limit = -1
	}
	return limit
}
